package com.lanou.myapp.funny.videofunny;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.lanou.myapp.R;
import com.squareup.picasso.Picasso;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by dllo on 16/1/25.
 */
public class VideoFunnyAdapter extends RecyclerView.Adapter<VideoFunnyAdapter.MyViewHolder> {
    private Context context;
    private List<VideoFunnyBeans.ListEntity> data;
    private String url;


//    public void setMyOnclick(MyOnclick myOnclick) {
//        this.myOnclick = myOnclick;
//    }

    public VideoFunnyAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<VideoFunnyBeans.ListEntity> data) {
        this.data = data;
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_funny_video, null);
        MyViewHolder myaViewHolder = new MyViewHolder(view);
        return myaViewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        url = data.get(position).getVideo().getVideo().get(0);
//        ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.circlelmage, R.mipmap.v6_boy_unseletor_icon, R.mipmap.v6_boy_unseletor_icon);
//        VolleySingleton.getImageLoader().get(data.get(position).getU().getHeader().get(0), listener,200,200);
        Picasso.with(context).load(data.get(position).getU().getHeader().get(0)).resize(200,200).into(holder.circlelmage);
//        Glide.with(context).load(data.get(position).getU().getHeader().get(0)).into(holder.circlelmage);


        holder.tv_author.setText(data.get(position).getU().getName());
        holder.tv_time.setText(data.get(position).getPasstime());
        holder.tv_title.setText(data.get(position).getText());
        holder.tv_praise.setText(data.get(position).getUp() + "");
        holder.tv_stamp.setText(data.get(position).getDown() + "");


//        if (myOnclick != null){
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    int pos = holder.getLayoutPosition();
//                    myOnclick.MyonClick(pos);
//                }
//            });
//        }

        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, VideoActivity.class);
                intent.putExtra("key", url);
                context.startActivity(intent);
            }
        });

    }


    @Override
    public int getItemCount() {
        return data != null ? data.size()/2 : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private CircleImageView circlelmage;
        private TextView tv_author, tv_time, tv_title, tv_praise, tv_stamp;

        public MyViewHolder(View itemView) {
            super(itemView);

            circlelmage = (CircleImageView) itemView.findViewById(R.id.iv_item_video_funny);
            imageView = (ImageView) itemView.findViewById(R.id.textureVideoView);
            tv_author = (TextView) itemView.findViewById(R.id.tv_name_video_funny);
            tv_time = (TextView) itemView.findViewById(R.id.tv_title_video_funny);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title_video_funny);
            tv_praise = (TextView) itemView.findViewById(R.id.tv_num_zan_video);
            tv_stamp = (TextView) itemView.findViewById(R.id.tv_num_video_funny_cai);

        }
    }
}
